<?php
namespace Admin\Controller;
use Think\Controller;
class NewsController extends AdminController {
	//新闻资讯
    public function index(){
    	$this->news=M('News')->select();
    	$this->count=M('News')->count();
    	$this->display();
    }
    //添加新闻资讯页面
    public function add_news_page(){
    	$this->display();
    }
    //添加新闻资讯
    public function add_news(){
    	$data['title']=I('title');
    	$data['content']=I('content');
    	$data['time']=time();
    	if(M('News')->add($data)){
    		echo 1;
    	}else{
    		echo 2;
    	}
    }
    //修改新闻资讯页面
    public function save_news_page(){
    	$id = I('id');
    	$this->news=M('News')->where("id='$id'")->find();
    	$this->assign('id',$id);
    	$this->display();
    }
    //修改新闻资讯
    public function save_news(){
    	$id = I('id');
    	$data['title']=I('title');
    	$data['content']=I('content');
    	$data['time']=time();
    	if(M('News')->where("id='$id'")->save($data)){
    		echo 1;
    	}else{
    		echo 2;
    	}
    }
    //删除
    public function del(){
    	$id = I('id');
    	if(M('News')->where("id='$id'")->delete()){
    		echo 1;
    	}else{
    		echo 2;
    	}
    }
}